package com.financial.business.yspay.mq;

import com.aliyun.openservices.ons.api.Consumer;
import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author WANGNING
 * @description 银盛金融中心消费者mq配置
 * @email wyn20140226@aliyun.com
 * @date 2019/11/14 9:06 AM
 */
@Configuration
public class FinancialYsMQConsumer {

    @Autowired
    private FinancialYsMessageListener financialYsMessageListener;

    public static final Logger LOGGER = LoggerFactory.getLogger(FinancialYsMQConsumer.class);

    public FinancialYsMQConsumer() {

    }

    @Bean
    public Consumer getYSAsynchronousSplitReceiptMQConsumerMsgListener() {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.GROUP_ID, FinancialYsMQConfig.GROUP_ID);
        properties.put(PropertyKeyConst.AccessKey, FinancialYsMQConfig.ACCESS_KEY);
        properties.put(PropertyKeyConst.SecretKey, FinancialYsMQConfig.SECRET_KEY);
        properties.put(PropertyKeyConst.NAMESRV_ADDR, FinancialYsMQConfig.NAMESRV_ADDR);
        Consumer consumer = ONSFactory.createConsumer(properties);
        try {
            consumer.subscribe(FinancialYsMQConfig.TOPIC, FinancialYsMQConfig.ALL_TAG, financialYsMessageListener);
            consumer.start();
            LOGGER.info("SettleConsumer is start !!!  groupId:{" + FinancialYsMQConfig.GROUP_ID + "}");
        } catch (Exception var4) {
            LOGGER.error(String.format("SettleConsumer is error  groupId:{" + FinancialYsMQConfig.GROUP_ID + "}", var4.getMessage(), var4));
        }
        return consumer;
    }
}

